<?php
class Ecore_Common extends Ecore_Db {
	var $cache;
	var $clear;
	public function __construct() {		
	}
	public function getVisitor($strSessionId) {
		try {		
			$this->prepare('call uonlines_addupdate(?);');
			$this->bindParam(1, $strSessionId, PDO::PARAM_STR, 100);
			$arrData = $this->fetchAll();			
			return isset($arrData[0]['vistior']) ? $arrData[0]['vistior'] : 0;
		}catch(Exception $e) {
			Ecore_Function::logDb('Ecore_Common::getVisitor - ' .$e->getMessage());			
			
		}		
	}
	public function getCountry($isCombobox=1) {
		try {
			
			$this->prepare('call com_getcountries();');
			$arrData = $this->fetchAll();
				
			if($isCombobox) {
				$arrResult = array();
				foreach($arrData as $value) {
					$arrResult[$value['code']] = $value['name'];
				}
				return $arrResult;
			}
			else
				return isset($arrData[0])?$arrData[0]:null;
		}catch(Exception $e) {
			Ecore_Function::logDb('Ecore_Common::getCountry - ' .$e->getMessage());			
			
		}		
	}
	public function getProvince($strCountry='VN',$isCombobox=1) {
		try {			
			$this->prepare('call com_getprovinces(?);');
			$this->bindParam(1, $strCountry, PDO::PARAM_STR, 2);
			$arrData = $this->fetchAll();
			if($isCombobox) {
				$arrResult = array();
				foreach($arrData as $value) {
					$arrResult[$value['provinceid']] = $value['name'];
				}
				return $arrResult;
			}else {
				return isset($arrData) ? $arrData : null;
			}
		}catch(Exception $e) {
			Ecore_Function::logDb('Ecore_Common::getProvince - ' .$e->getMessage());			
			
		}		
	}
	public function getDistrict($intProvinceId,$isCombobox=1) {
		try {			
			$this->prepare('call com_getdistricts(?);');
			$this->bindParam(1, $intProvinceId, PDO::PARAM_INT,11);
			$arrData = $this->fetchAll();			
			if($isCombobox) {
				$arrResult = array();
				foreach($arrData as $value) {
					$arrResult[$value['districtid']] = $value['name'];
				}
				return $arrResult;
			}else {
				return isset($arrData[0])?$arrData[0]:null;
			}
		}catch(Exception $e) {
			Ecore_Function::logDb('Ecore_Common::getDistrict - ' .$e->getMessage());			
			
		}		
	}	
}